package com.example.mardan_demo1.config;

import com.example.mardan_demo1.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;


@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private RequestLoggingInterceptor requestLoggingInterceptor;

    // 放行的路径数组
    private static final String[] EXCLUDE_PATHS = {
            "/user/login",
            "/user/register",
            "src/main/resources/public",  // 放行所有静态资源
            "/favicon.ico", // 放行 favicon.ico
            "/", // 放行根路径
            "/h",
            "/sj-yaopin/houxuanlist",
            "/user/qiye-zhuce",
            "/huiyi-api/gethuiyilist",
            "/huiyi-api/huoquhuiyiyitibyid",
            "/huiyi-api/getyitibyid",
            "/huiyi-api/gethuiyilistbyipaddress",
            "/huiyi-api/getIpAddressForClient",
            "/huiyi-api/shouquan-yonghu-gethuiyilist"
    };


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(EXCLUDE_PATHS); // 添加放行路径
        //打印请求参数
        registry.addInterceptor(requestLoggingInterceptor);
    }
    
    /*
     *解决resources下面静态资源无法访问
     * @param registry
     * @Author:  买尔旦江
     * @date:   
     */
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/favicon.ico")
//                .addResourceLocations("classpath:/static/");
//        super.addResourceHandlers(registry);
//    }
//
}
